package com.itheima.tliaswebmanagement.controller;

import com.itheima.tliaswebmanagement.pojo.entity.Dept;
import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.itheima.tliaswebmanagement.service.TliasService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TliasController
 * @Author ziguan ling
 * @Date 2025--01--02
 */

@RestController
@Slf4j
public class TliasController {
    @Autowired
    @Qualifier("tliasServiceImpl")
    private TliasService tliasService;

    @GetMapping("/depts")
    Result list() {
        List<Dept> list = tliasService.queryAll();
        log.info("查询所有部门");
        return Result.success(list);
    }

    @DeleteMapping("/depts")
    public Result removeList(Integer id) {
//        System.out.println("删除部门" + id);
        log.info("删除部门" + id);
        tliasService.removeList(id);
        return Result.success();
    }


    @PostMapping("/depts")
    public  Result addDept(@RequestBody Dept dept){
//        System.out.println("添加部门"+dept);
        log.info("添加部门"+dept);
        tliasService.addDept(dept);
        return Result.success();
    }

    @GetMapping("depts/{id}")
    public Result getInfo(@PathVariable Integer id){
//        System.out.println("根据ID查询部门数据:" + id);
        log.info("根据ID查询部门数据:" + id);
        Dept dept = tliasService.getinfo(id);

        return Result.success(dept);
    }

    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
//        System.out.println("修改部门数据"+ dept);
        log.info("修改部门数据"+ dept);
        tliasService.update(dept);
        return Result.success();
    }
}
